
******************************************
*******Code for household analysis *******
******************************************
use ...household_data.dta,clear 


sum  hh_ndvi_ln ///
       hp_subside_criterion_index_ihs hp_subside_money_ihs_new ///
       b1_manage_area_ha00 ///
	   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
	   pastoral_num  ///
	   head_nonpastorl ///
	   folk_pastoral_ornot ///
	   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
       prcp5_9 tavg5_9 v_disaster year ///
	   hhcode_num yrvcode ///
	   total_income_per_ihs_new pastoral_income_per_ihs_new non_pastoral_income_per_ihs_new non_program_income_per_ihs_new ///
	   county_grassland_type ///
	   b1_manage_area_ha00_per_ihs hh_road_distance labor_edu /// 
	   hp_subside_ihs_int1_per hp_subside_ihs_int2_per hp_subside_ihs_int3_per /// 
	   all_end_ihs cattle_end_ihs sheep_end_ihs gf_weight_all_per_kg_ihs rentin_yesno /// 
	   interland b1_per_ha100_ihs_minus interfolk intercheck interwage ///
	   all_end_ihs cattle_end_ihs sheep_end_ihs gf_weight_all_per_kg_ihs rentin_yesno hp_subside_criterion_index_ihs


**** Table 1. col.(3)- impact on grassland quality-household level 
	areg hh_ndvi_ln ///
       hp_subside_criterion_index_ihs ///
       b1_manage_area_ha00 ///
	   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
	   pastoral_num  ///
	   head_nonpastorl ///
	   i.folk_pastoral_ornot ///
	   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
       prcp5_9 tavg5_9 i.v_disaster i.year ///
	   , absorb(hhcode_num) cluster(yrvcode)
	   
	   
**** Table 2. Panel A. overall impacts on income 
	
		foreach var in total_income_per_ihs_new pastoral_income_per_ihs_new non_pastoral_income_per_ihs_new non_program_income_per_ihs_new {
			 areg `var' ///
			   hp_subside_money_ihs_new  ///
				   b1_manage_area_ha00  ///
				   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
				   pastoral_num  ///
				   head_nonpastorl ///
				   i.folk_pastoral_ornot ///
				   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
				   prcp5_9 tavg5_9 i.v_disaster i.year ///
				   , absorb(hhcode_num) cluster(yrvcode)
			}
			

 	
**** Table 2. Panel B.  impacts on income by grassland type 
		foreach var in total_income_per_ihs_new pastoral_income_per_ihs_new non_pastoral_income_per_ihs_new non_program_income_per_ihs_new {
				areg `var' ///
					hp_subside_money_ihs_new ///
						b1_manage_area_ha00  ///
						b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
						pastoral_num  ///
						head_nonpastorl ///
						i.folk_pastoral_ornot ///
						vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
						prcp5_9 tavg5_9 i.v_disaster i.year ///
						if county_grassland_type==5|county_grassland_type==7|county_grassland_type==17, absorb(hhcode_num) cluster(yrvcode)
					
				areg `var' ///
					hp_subside_money_ihs_new ///
						b1_manage_area_ha00  ///
						b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
						pastoral_num  ///
						head_nonpastorl ///
						i.folk_pastoral_ornot ///
						vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
						prcp5_9 tavg5_9 i.v_disaster i.year ///
						if county_grassland_type==6|county_grassland_type==14 ///
						, absorb(hhcode_num) cluster(yrvcode)
					
				areg `var' ///
					hp_subside_money_ihs_new ///
						b1_manage_area_ha00  ///
						b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
						pastoral_num  ///
						head_nonpastorl ///
						i.folk_pastoral_ornot ///
						vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
						prcp5_9 tavg5_9 i.v_disaster i.year ///
						if county_grassland_type==16|county_grassland_type==18|county_grassland_type==19 ///
						, absorb(hhcode_num) cluster(yrvcode)
    }

**** Table 2. Panel C.  impacts on income by socioeconomic variables  
	   *** Education 
			foreach var in total_income_per_ihs_new pastoral_income_per_ihs_new non_pastoral_income_per_ihs_new non_program_income_per_ihs_new {
			 areg `var' ///
			   hp_subside_money_ihs_new c.hp_subside_money_ihs_new#c.labor_edu  ///
				   b1_manage_area_ha00  ///
				   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
				   pastoral_num  ///
				   head_nonpastorl ///
				   i.folk_pastoral_ornot ///
				   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
				   prcp5_9 tavg5_9 i.v_disaster i.year ///
				   , absorb(hhcode_num) cluster(yrvcode)
			}

	   *** Road 
		   foreach var in total_income_per_ihs_new pastoral_income_per_ihs_new non_pastoral_income_per_ihs_new non_program_income_per_ihs_new {
			 areg `var' ///
			   hp_subside_money_ihs_new c.hp_subside_money_ihs_new#c.hh_road_distance  ///
				   b1_manage_area_ha00  ///
				   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
				   pastoral_num  ///
				   head_nonpastorl ///
				   i.folk_pastoral_ornot ///
				   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
				   prcp5_9 tavg5_9 i.v_disaster i.year ///
				   , absorb(hhcode_num) cluster(yrvcode)
			}

	   *** Grassland area per capita  
		   foreach var in total_income_per_ihs_new pastoral_income_per_ihs_new non_pastoral_income_per_ihs_new non_program_income_per_ihs_new {
			 areg `var' ///
			   hp_subside_money_ihs_new c.hp_subside_money_ihs_new#c.b1_manage_area_ha00_per_ihs  ///
				   b1_manage_area_ha00  ///
				   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
				   pastoral_num  ///
				   head_nonpastorl ///
				   i.folk_pastoral_ornot ///
				   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
				   prcp5_9 tavg5_9 i.v_disaster i.year ///
				   , absorb(hhcode_num) cluster(yrvcode)
			}

			
**** Table 3. impacts on income equity 
		foreach var in total_income_per_ihs_new pastoral_income_per_ihs_new non_pastoral_income_per_ihs_new  {
			 areg `var' ///
			   hp_subside_ihs_int1_per hp_subside_ihs_int2_per hp_subside_ihs_int3_per  ///
				   b1_manage_area_ha00  ///
				   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
				   pastoral_num  ///
				   head_nonpastorl ///
				   i.folk_pastoral_ornot ///
				   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
				   prcp5_9 tavg5_9 i.v_disaster i.year ///
				   , absorb(hhcode_num) cluster(yrvcode)
			}
			

**** Table 5. impacts on herder behavior 

	foreach var in all_end_ihs cattle_end_ihs sheep_end_ihs gf_weight_all_per_kg_ihs rentin_yesno {
		areg `var' ///
       hp_subside_criterion_index_ihs ///
       b1_manage_area_ha00 ///
	   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
	   pastoral_num  ///
	   head_nonpastorl ///
	   i.folk_pastoral_ornot ///
	   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
        i.v_disaster i.year ///
	   tavg5_9 prcp5_9 , absorb(hhcode_num) cluster(yrvcode)
		}
		
		
**** Table 7. heterogenous impacts 
	areg hh_ndvi_ln ///
       hp_subside_criterion_index_ihs interland b1_per_ha100_ihs_minus ///
       b1_manage_area_ha00 ///
	   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
	   pastoral_num  ///
	   head_nonpastorl ///
	   i.folk_pastoral_ornot ///
	   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
       i.v_disaster i.year ///
	   tavg5_9 prcp5_9, absorb(hhcode_num) cluster(yrvcode)

	areg hh_ndvi_ln ///
       hp_subside_criterion_index_ihs interfolk ///
       b1_manage_area_ha00 ///
	   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
	   pastoral_num  ///
	   head_nonpastorl ///
	   i.folk_pastoral_ornot ///
	   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
       tavg5_9 prcp5_9 i.v_disaster i.year ///
	   , absorb(hhcode_num) cluster(yrvcode)

	areg hh_ndvi_ln ///
       hp_subside_criterion_index_ihs intercheck ///
       b1_manage_area_ha00 ///
	   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
	   pastoral_num  ///
	   head_nonpastorl ///
	   i.folk_pastoral_ornot ///
	   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
       tavg5_9 prcp5_9 i.v_disaster i.year ///
	   , absorb(hhcode_num) cluster(yrvcode)

	areg hh_ndvi_ln ///
       hp_subside_criterion_index_ihs interwage ///
       b1_manage_area_ha00 ///
	   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
	   pastoral_num  ///
	   head_nonpastorl ///
	   i.folk_pastoral_ornot ///
	   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
       tavg5_9 prcp5_9 i.v_disaster i.year ///
	   , absorb(hhcode_num) cluster(yrvcode)
	   
	   
	   
	   
	   
**** Supplementary Table 4. pre-trend assumptions
   *** Table S4. Pre-trend tests
    gen pcode=int(hhcode_num/100000)
	
	g temp=hp_subside_criterion_index_ihs if year==2015
	bysort hhcode_num: egen hp2015=max(temp)
	drop temp
	
	g temp=hp_subside_criterion_index_ihs if year==2016
	bysort hhcode_num: egen hp2016=max(temp)
	drop temp
	
	g temp=hp_subside_criterion_index_ihs if year==2017
	bysort hhcode_num: egen hp2017=max(temp)
	drop temp
	
	egen hpmn=rmean(hp2015 hp2016 hp2017)
	
    for num 2008/2010 2015/2017: g yrX=year==X
	for num 2008/2010 2015/2017: g inter15X=yrX*hp2015
	for num 2008/2010 2015/2017: g inter16X=yrX*hp2016
	for num 2008/2010 2015/2017: g inter17X=yrX*hp2017	
	for num 2008/2010 2015/2017: g intermnXa=yrX*hpmn		

    areg hh_ndvi_ln ///
       intermn2008-intermn2009 intermn2015-intermn2017 ///
       b1_manage_area_ha00 ///
	   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
	   pastoral_num  ///
	   head_nonpastorl ///
	   i.folk_pastoral_ornot ///
	   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
       rain5_9 tavg5_9 i.v_disaster i.year ///
	   if pcode==2|pcode==3, absorb(hhcode_num) cluster(yrvcode)
	outreg2 using $output4\pre-test1.xls, replace bd(3) sd(3) pvalue
	
	foreach var in all_end_ihs cattle_end_ihs sheep_end_ihs gf_weight_all_per_kg_ihs rentin_yesno {
		areg `var' ///
         intermn2008-intermn2009 intermn2015-intermn2017 ///
		   b1_manage_area_ha00 ///
		   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
		   pastoral_num  ///
		   head_nonpastorl ///
		   i.folk_pastoral_ornot ///
		   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
		   rain5_9 tavg5_9 i.v_disaster i.year ///
		   if pcode==2|pcode==3, absorb(hhcode_num) cluster(yrvcode)
		outreg2 using $output4\pre-test1.xls, append bd(3) sd(3) pvalue
		}
	
	   
****** Supplementary Table 9. FE& RE on herder income 
	   drop if hhcode==""
	   drop if total_income_per_ihs_new==.
	   xtset hhcode_num year

	
		foreach var in total_income_per_ihs_new pastoral_income_per_ihs_new non_pastoral_income_per_ihs_new  {
			 xtreg `var' ///
			   hp_subside_money_ihs_new  ///
				   b1_manage_area_ha00  ///
				   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
				   pastoral_num  ///
				   head_nonpastorl ///
				   i.folk_pastoral_ornot ///
				   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
				   prcp5_9 tavg5_9 i.v_disaster i.year ///
				   ,fe 
		  }
		  
		foreach var in total_income_per_ihs_new pastoral_income_per_ihs_new non_pastoral_income_per_ihs_new  {
			xtreg `var' ///
			   hp_subside_money_ihs_new  ///
				   b1_manage_area_ha00  ///
				   b1_number_plot alliance_manage_pct b3_clip_ornot b3_grass_ornot b3_fodder_ornot ///
				   pastoral_num  ///
				   head_nonpastorl ///
				   i.folk_pastoral_ornot ///
				   vprice_cattle_t_indexln vprice_sheep_t_indexln vprice_dg_t_indexln twage000_indexln trent_rent_fee_indexln ///
				   prcp5_9 tavg5_9 i.v_disaster i.year ///
				   , re 
}
